﻿using System.Reflection;
using System.Web.Mvc;
using Castle.MicroKernel.Registration;
using Castle.Windsor;

namespace Genesis.Infrastructure.Web.Extensions
{

    public static class IWindsorContainerExtensions
    {

        public static IWindsorContainer RegisterControllers(this IWindsorContainer windsorContainer, Assembly assembly)
        {

            windsorContainer.Register(AllTypes.Of<Controller>().FromAssembly(assembly).Configure(c => c.LifeStyle.Transient.Named(c.Implementation.Name.ToLower())));

            return windsorContainer;

        }

        public static IWindsorContainer RegisterControllers(this IWindsorContainer windsorContainer, AssemblyName assemblyName)
        {

            windsorContainer.RegisterControllers(Assembly.Load(assemblyName));

            return windsorContainer;

        }

        public static IWindsorContainer RegisterControllers(this IWindsorContainer windsorContainer, string assemblyName)
        {

            windsorContainer.RegisterControllers(new AssemblyName(assemblyName));

            return windsorContainer;

        }

    }

}